package oop.ex2.main;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Implements the Interpreter as specified in the assignment.
 * This class accepts commands from the standard input and attempts to process them using a LineProccessor.
 * If an exception was encountered, an error message is printed and the program continues to accept input.
 * @author daniel_i_l
 *
 */
public class InterpreterMain {
	private static final String EXIT_STRING = "quit";
	private static final String ERROR_MESSAGE = "ERROR";
	
	/**
	 * This is the function that runs the interpreter. It reads lines of input one by one and passes it to a LineParser.
	 * The LineParser is in charge of parsing the command and printing any output if necessary.
	 * @param args No arguments are handled.
	 */
	public static void main(String[] args) {
		
		LineProcessor lineProcessor = new LineProcessor();
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		String input;
		
		while (true) {
			try {
				input = bufferedReader.readLine();
				if (input.equals(EXIT_STRING))
					break;
				lineProcessor.processLine(input);
			} catch (Exception e) {
				System.err.println(ERROR_MESSAGE);
			}
		}
	}

}
